package com.csg.ses.controller;

import com.csg.ses.common.annotation.LoginToken;
import com.csg.ses.entity.ses.GroupInfoEntity;
import com.csg.ses.entity.ses.NewsInfoEntity;
import com.csg.ses.vo.common.Result;
import com.csg.ses.vo.common.ResultStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.csg.ses.vo.common.IdListVo;
import java.util.List;
import com.csg.ses.service.ses.GroupInfoService;

/**
 * 
 * @author cjj
 * @date 2021-04-11 11:20:47
 */
@RestController
@RequestMapping("/groupInfo")
@Api(tags = "接口")
public class GroupInfoController {
    @Autowired
    private GroupInfoService groupInfoService;

    /**
     * 列表
     */
    @ApiOperation(value = "列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "groupInfo", value = "", dataType = "GroupInfoEntity", paramType = "body"),
        @ApiImplicitParam(name = "current", value = "当前页", required = true ,dataType = "Integer"),
        @ApiImplicitParam(name = "size", value = "每页记录数", required = true ,dataType = "Integer")
    })
    @GetMapping("/list")
    @LoginToken
    public Result<List<GroupInfoEntity>> list(GroupInfoEntity groupInfo, Long current, Long size) {
        return groupInfoService.retrieve(groupInfo, current, size);
    }

    @GetMapping("/listAll")
    @LoginToken
    public Result<List<NewsInfoEntity>> list() {
        return groupInfoService.queryAllGroup();
    }

    /**
     * 删除
     * @param idList
     * @return
     */
    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "idList", value = "ID数组", dataType = "IdListVo", paramType = "body", required = true)
    @DeleteMapping("/del")
    @LoginToken
    public Result<String> del(@RequestBody IdListVo idList) {
        return groupInfoService.del(idList);
    }

    @ApiOperation(value = "根据id查找")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String", required = true)
    @GetMapping("/{id}")
    @LoginToken
    public Result<GroupInfoEntity> getById(@PathVariable String id) {
        return groupInfoService.getById(id);
    }

    /**
     * 保存
     * @param
     * @return
     */
    @ApiOperation(value = "保存")
    @ApiImplicitParam(name = "groupInfo", value = "", dataType = "GroupInfoEntity", paramType = "body")
    @PostMapping("/save")
    @LoginToken
    public Result<String> save(@RequestBody GroupInfoEntity groupInfo) {
        boolean result = groupInfoService.save(groupInfo);
        if (result) {
            return new Result("保存成功！", ResultStatus.SUCCESS);
        } else {
            return new Result("保存失败！", ResultStatus.FAILED);
        }
    }
}